#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
//题目 1115: DNA
void print(ll a)
{
    //上半部分
    for (ll i = 2; i <= a / 2; i++)
    {
        for (ll j = 1; j <= a - i + 1; j++)
        {
            if (j == i || j == a - i + 1)
                cout << "X";
            else
                cout << " ";
        }
        cout << endl;
    }
    //下半部分
    for (ll i = a / 2 + 1; i <= a; i++)
    {
        for (ll j = 1; j <= i; j++)
        {
            if (j == a - i + 1 || j == i)
                cout << "X";
            else
                cout << " ";
        }
        cout << endl;
    }
}

int main()
{
    IOS;
    ll n, a, b;
    while (cin >> n)
    {
        while (n--)
        {
            cin >> a >> b;
            for(ll i=1;i<=a;i++){
                if(i==1||i==a)cout<<"X";
                else cout<<" ";
            }
            cout<<endl;
            while (b--)
            {
                print(a);
            }
            if (n > 0)
                cout << endl;
        }
    }
    getchar();
    getchar();
    return 0;
}
